/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Building")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Building.findAll", query = "SELECT b FROM Building b"),
    @NamedQuery(name = "Building.findByUnit", query = "SELECT b FROM Building b WHERE b.unit = :unit"),
    @NamedQuery(name = "Building.findBySpace", query = "SELECT b FROM Building b WHERE b.space = :space"),
    @NamedQuery(name = "Building.findByMasonNum", query = "SELECT b FROM Building b WHERE b.masonNum = :masonNum")})
public class Building implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "unit")
    private Integer unit;
    @Basic(optional = false)
    @NotNull
    @Column(name = "space")
    private int space;
    @Column(name = "masonNum")
    private Integer masonNum;
    @JoinColumn(name = "unit", referencedColumnName = "id", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Unit unit1;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "building1")
    private Factory factory;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "building1")
    private Collection<Build> buildCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "building1")
    private MilitaryBuilding militaryBuilding;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "building1")
    private House house;

    public Building() {
    }

    public Building(Integer unit) {
        this.unit = unit;
    }

    public Building(Integer unit, int space) {
        this.unit = unit;
        this.space = space;
    }

    public Integer getUnit() {
        return unit;
    }

    public void setUnit(Integer unit) {
        this.unit = unit;
    }

    public int getSpace() {
        return space;
    }

    public void setSpace(int space) {
        this.space = space;
    }

    public Integer getMasonNum() {
        return masonNum;
    }

    public void setMasonNum(Integer masonNum) {
        this.masonNum = masonNum;
    }

    public Unit getUnit1() {
        return unit1;
    }

    public void setUnit1(Unit unit1) {
        this.unit1 = unit1;
    }

    public Factory getFactory() {
        return factory;
    }

    public void setFactory(Factory factory) {
        this.factory = factory;
    }

    @XmlTransient
    public Collection<Build> getBuildCollection() {
        return buildCollection;
    }

    public void setBuildCollection(Collection<Build> buildCollection) {
        this.buildCollection = buildCollection;
    }

    public MilitaryBuilding getMilitaryBuilding() {
        return militaryBuilding;
    }

    public void setMilitaryBuilding(MilitaryBuilding militaryBuilding) {
        this.militaryBuilding = militaryBuilding;
    }

    public House getHouse() {
        return house;
    }

    public void setHouse(House house) {
        this.house = house;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (unit != null ? unit.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Building)) {
            return false;
        }
        Building other = (Building) object;
        if ((this.unit == null && other.unit != null) || (this.unit != null && !this.unit.equals(other.unit))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Building[ unit=" + unit + " ]";
    }
    
}
